from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, Boolean, BigInteger
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class DHTNode(Base):
    """DHT节点表"""
    __tablename__ = 'dht_nodes'
    
    id = Column(Integer, primary_key=True)
    node_id = Column(String(40))  # 节点ID的hex字符串
    ip = Column(String(64))
    port = Column(Integer)
    first_seen = Column(DateTime, default=datetime.utcnow)
    last_active = Column(DateTime, default=datetime.utcnow)
    is_active = Column(Boolean, default=True)
    success_count = Column(Integer, default=0)
    failed_count = Column(Integer, default=0)
    
class InfoHash(Base):
    """InfoHash记录表"""
    __tablename__ = 'info_hashes'
    
    id = Column(Integer, primary_key=True)
    info_hash = Column(String(40), unique=True)  # info_hash的hex字符串
    first_seen = Column(DateTime, default=datetime.utcnow)
    last_seen = Column(DateTime, default=datetime.utcnow)
    announce_count = Column(Integer, default=1) 